window.onload = function(){
	window.banner = document.getElementById('banner');
	window.bgBox = document.getElementById('bgBox');
	window.leftBtn = document.getElementById('leftBtn');
	window.rightBtn = document.getElementById('rightBtn');
	window.projects = document.getElementsByClassName('project');
	window.animType = false;
	
	addBtnEvent();
	
	for(var i = 0; i<projects.length;i++){
		projects[i].onmouseover = function(){
			this.children[0].style.display = 'none';
			this.children[0].nextSibling.nextSibling.style.backgroundSize = 120 + '%';
		}
		projects[i].onmouseout = function(){
			this.children[0].style.display = 'block';
			this.children[0].nextSibling.nextSibling.style.backgroundSize = 100 + '%';
		}
	}
}

//添加点击侦听事件
function addBtnEvent(){
	leftBtn.onclick = function(){
		imgMove(-1200,-10);
	}
	rightBtn.onclick = function(){
		imgMove(1200,10);
	}
}

function imgMove(speed,moveSpeed){
	
	var curr = getStyle(bgBox,'left');
	
	if(curr == 0){
		bgBox.style.left = -3600 + 'px';
	}else if(curr == -4800){
		bgBox.style.left = -1200 + 'px';
	}
	
	var target = getStyle(bgBox,'left') + speed;
	
	startMove(target,speed,moveSpeed);

	animType = true;
}

var time = null;

function startMove(target,speed,moveSpeed){
	clearInterval(time);
	time = setInterval(function(){
		var curr = getStyle(bgBox,'left');
		if(curr==target){
			clearInterval(time);
			animType = false;
			addBtnEvent();
		}else{
			bgBox.style.left = curr + moveSpeed + 'px';
			leftBtn.onclick = null;
			rightBtn.onclick = null;
		}
	},10);
	
}

function   getStyle(obj,attr){

    if(obj.currentStyle){
        return  parseInt(obj.currentStyle[attr]);
    }else{
        return  parseInt(getComputedStyle(obj,false)[attr]);
    }
}